<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>product</title>
    <script type="text/javascript" src="../frame/assets/js/lib/jquery.min.js"></script>
	<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script src="../frame/layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" href="../frame/layui/lay/modules/layer/default/layer.css">
    <link rel="stylesheet" href="../frame/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../frame/assets/css/lib/bootstrap.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/font-awesome.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/themify-icons.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/unix.css">
    <link rel="stylesheet" href="../frame/assets/css/style.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/menubar/sidebar.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/sweetalert/sweetalert.css">
</head>
<body>
<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <!--欢迎栏-->
            <div class="row">
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>资产调动管理</h1>
                         
                           <!-- <span>先编辑，后借用</span> -->
                        </div>
                    </div>
                </div>
             </div>
             <table id="demo1" lay-filter="test1"></table>
				<br><br>
         </div>  
    </div>
</div>
<!--搜索-->
<div id="search">
    <button type="button" class="close">×</button>
    <form>
        <input type="search" value="" placeholder="type keyword(s) here" />
        <button type="submit" class="btn btn-primary">Search</button>
    </form>
</div>
<script type="text/html" id="barDemo1">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">报废</a>   	
</script>
<script src="../frame/assets/js/lib/jquery.min.js"></script>
<script src="../frame/assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="../frame/assets/js/lib/menubar/sidebar.js"></script>
<script src="../frame/assets/js/lib/bootstrap.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/dataTables.buttons.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.flash.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/jszip.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/pdfmake.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/vfs_fonts.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.html5.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.print.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables-init2.js"></script>
<script src="../frame/assets/js/lib/sweetalert/sweetalert.min.js"></script>
<script src="../frame/assets/js/lib/sweetalert/zhuxiao.js"></script>
<script type="text/javascript" src="../frame/layui/layui.js" charset="utf-8"></script>

<script>
layui.use('table', function()
{
  var table = layui.table;
  //第一个实例
  table.render({
    elem: '#demo1'
    ,height: '450px'
    ,url: 'selectuseproduct' //数据接口
    ,method:'get'
    ,page: true //开启分页
    ,cols: [[ //表头
      {field:'sid', width:90, title: 'ID编号', sort: true,fixed:'left'}
      ,{field:'sname', width:120, title: '资产名称'}
      ,{field:'sperson', width:100, title: '审核人'}
      ,{field:'speople', width:100, title: '借调人'}
      ,{field:'sbegint',width:120, title: '日期', sort: true}
      ,{field:'scondition',width:90, title: '状态'}
      ,{field:'right', width:120, title: '操作',toolbar:'#barDemo1'}
    ]]
  });

  //监听行事件
   table.on('tool(test1)', function(obj){
	var data = obj.data;var sid=data.sid; 
    if(obj.event === 'del'){
    	if(data.scondition=="已借用")
   			{
   				alert("不可借用");
   				return 0;
   			}
      layer.confirm('报废么',{btn:['确定','取消']}
   		 ,function(index)
   		 {
   			
     		 obj.del();
     		 usebyid(data);
             layer.close(index);
   		 })
    } else if(obj.event === 'edit'){
		//实现编辑
		if(data.scondition=="已借用")
		{
			alert("不可编辑");
			return 0;
		}
			
		layer.open({
			type:2
			,title:"编辑借调信息"
			,content:'edituseproduct.html'
			,maxmin:true
			,area:['700px']['600px']
			,btn:['确认','撤销']
			,yes:function(index,layero){
				//回调的数值,取输入框的内容
				var sid=$(layero).find('iframe')[0].contentWindow.sid.value;	
				var sname=$(layero).find('iframe')[0].contentWindow.sname.value;
				var sperson=$(layero).find('iframe')[0].contentWindow.sperson.value;
				var speople=$(layero).find('iframe')[0].contentWindow.speople.value;
				var sbegint=$(layero).find('iframe')[0].contentWindow.sbegint.value;
				var scondition=$(layero).find('iframe')[0].contentWindow.scondition.value;
				//同步数据表格
				obj.update({
					'sid':sid,
					'sname':sname,
					'sperson':sperson,
					'speople':speople,
					'sbegint':sbegint,
					'scondition':scondition
				})
				
			     $.ajax({
					url:'edituseproduct?sid='+sid+"&sname="+sname+"&sperson="+sperson+"&speople="+speople+"&sbegint="+sbegint+"&scondition="+scondition,
					type:'post',
					contentType:'application/json;charset=utf-8',
					dataType:'text',
					data:{
						'sid':sid,
						'sname':sname,
						'sperson':sperson,
						'speople':speople,
						'sbegint':sbegint,
						'scondition':scondition
					},
					success:function(res){
						layer.msg("编辑成功");
					},
					error:function(res){
						layer.msg("编辑失败！");
					}
				})
				layer.close(index);
			 }
			,success:function(layero,index){
				var div=layero.find('iframe').contents().find('#usage');
				var body=layer.getChildFrame('body',index);
				var iframeWindow=window['layui-layer-iframe'+index]
				body.find('#sid').val(data.sid);
				body.find('#sname').val(data.sname);
				body.find('#sperson').val(data.sperson);
				body.find('#speople').val(data.speople);
				body.find('#sbegint').val(data.sbegint);
				body.find('#scondition').val(data.scondition);
			}
		})
     }//编辑完成
     
   });//监听
})
 
  function usebyid(data){
	 var sid=data.sid;
	 var sname=data.sname;
	 var sperson=data.sperson;
	 var speople=data.speople;
	 var sbegint=data.sbegint;
	 var scondition=data.scondition;
	 //console.log(sname);
	 $.ajax({
		 type:"post",
		 url:'useproduct',
		 data:{
			 'sid':sid,
			 'sname':sname,
			 'sperson':sperson,
			 'speople':speople,
			 'sbegint':sbegint,
			 'scondition':scondition
		 },
		 dataType:'text',
		 success:function(res)
		 {
			 alert("成功");
		 },
		 error:function(XMLHttpRequest,textStatus,errorThrown)
		 {
			 alert(typeof(errorThrown));
		 }
	 });
  }//功能完毕   
  
 </script>
</body>
</html>